<template>
   
</template>

<script>
import vue from "vue";
import { h } from "vue";
console.log(11111, h)

console.log(11111, h)
const myForm = {
    data() {
        return {};
    },
    render(h) {
        return h("span", { class: "bar", innerHTML: "按钮1" });
    },
}; // 为了防止警告.
// 请求接口配置项
const { doTableData, doDelete } = {
    doTableData: function (params) {
        const aaaaaa = "/aaaaa";
        return klcs.ajaxTest({ url: aaaaaa, params: params });
    },
    doDelete: function (params) {
        const bbbbbb = "/bbbbb";
        return klcs.ajaxTest({ url: bbbbbb, params: params });
    },
};
// 参数配置项
const myOptions = {
    idName: "nnnnn",
    pickerFormat: "YYYY-MM-DD", // YYYY-MM-DD HH:mm:ss
    timeArrayValueName: ["start1", "end1"],
};


export default {
    components: { myForm },
    props: {
        value: {
            //对象
            type: Object,
            default: () => {
                return {};
            },
        },
    },
    data() {
        return {
            data: {
                loading: true,
                selectedRowKeys: [],
                formData: {
                    // 表单数据源
                    ssss: moment(new Date()).format(myOptions.pickerFormat),
                    timeArray: [
                        moment(new Date())
                            .subtract(1, "day")
                            .format(myOptions.pickerFormat),
                        moment(new Date()).format(myOptions.pickerFormat),
                    ],
                },
                dialogType: "add", // 弹窗类型
                nowDialogData: {},
                tableData: [],
                pageInfo: {
                    pageParams: { [klcs.pageNumberName]: 1, [klcs.pageSizeName]: 10 },
                    pageTotal: 0,
                },
            },
        };
    },
    created() { },
    mounted() {

        this.getTableDate();
    },
    watch: {
        aaaa: {
            handler(val) {
                //监听value的变化
            },
            deep: true,
            immediate: true,
        },
    },
    computed: {},
    methods: {
        getTableDate() {
            var params = {
                ...this.data.pageInfo.pageParams, // 页码参数处理
                ...this.data.formData, // 表单参数映射
                // 其他特殊处理.....
            };

            params = klcs.deleteEmptyArray(params); // 删除空数组属性
            params = klcs.spliceAndDeleteArray(
                "timeArray",
                params,
                myOptions["timeArrayValueName"]
            ); // 数组模式的参数特殊处理
            params = klcs.arrayToString(params, ["aaa", "bbb"]); // 转化数组为字符串

            console.log("提交输出的参数为: ", params);

            this.data.loading = true;
            doTableData().then((response) => {
                // 表格接口回调处.
                this.data.tableData = klcs.disposeData(response);
                this.data.loading = false;
                this.data.pageInfo.pageTotal = klcs.getTotal(response);
            });
        },
        onDelete(row) {
            var id = row[myOptions.idName];
            // this.$message.success("1111")
            // 询问框
            this.$confirm("确认要删除吗", "提示", {
                confirmButtonText: "确认",
                cancelButtonText: "关闭",
                callback: (action) => {
                    if (action == "confirm") {
                        // ElMessage({ type: 'success', message: `成功！` })
                        // this.data.tableData.splice(index, 1);
                        doDelete().then((response) => {
                            this.$message.success("成功！");
                            this.resetPage();
                            this.getTableDate();
                        });
                    }
                },
            });
        },
        onFormSure() {
            this.getTableDate();
        },
        resetPage() {
            this.data.pageInfo.pageParams[klcs.pageNumberName] = 1;
        },
        onRowClick(record, index) {
            //console.log("当前行:", record) // 行点击
        },
        onSelectChange(selectedRowKeysParams, selectedRows) {
            console.log(selectedRowKeysParams);
            this.data.selectedRowKeys = selectedRowKeysParams;
        }, // 选择
        onChangePage(page, pageSize) {
            this.getTableDate();
        },
        onSure() {
            this.resetPage();
            this.getTableDate();
        },
        resetForm() {
            this.$refs.formRef.resetFields();
            this.resetPage();
            this.getTableDate();
        },
        disabledDate(time) {
            return time.getTime() > Date.now();
        },
    },
};
</script>
